import { GSprite } from "../../../../com/mui/controls/GSprite";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { FahunRoleItem } from "./FahunRoleItem";
import { FahunItem } from "./FahunItem";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
//class FahunListPanel
    
    export  class FahunListPanel extends GSprite
    {
        constructor()
        {
            super();
            this._fahunArray = [];
            return;
        }

        public set isClickOpen(arg1: Boolean)
        {
            this._isClickOpen = arg1;
            return;
        }

        public updateFahunList(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            while (loc3 < this._fahunArray.length) 
            {
                loc1 = this._fahunArray[loc3];
                loc2 = arg1[loc3];
                loc1.fahunItemInfo = loc2;
                if (loc2.isEnable) 
                {
                    loc1.filters = null;
                    loc1.buttonMode = true;
                }
                else 
                {
                    loc1.filters = [FilterConst.colorFilter];
                    loc1.buttonMode = false;
                }
                loc1.isLight = loc2.isEnable;
                ++loc3;
            }
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            var loc1=null;
            super.createDisposedChildrenImpl();
            var loc2=0;
            while (loc2 < 5) 
            {
                loc1 = new FahunRoleItem();
                loc1.move(loc2 * 50, 0);
                this.addChild(loc1);
                loc1.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
                this._fahunArray.push(loc1);
                ++loc2;
            }
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!this._isClickOpen) 
            {
                return;
            }
            var loc1=arg1.target as FahunItem;
            var loc2=0;
            var loc3=-1;
            if (loc1 && loc1.fahunItemInfo) 
            {
                if (loc1.fahunItemInfo.isEnable) 
                {
                    loc3 = (loc1.fahunItemInfo.index - 1);
                }
                if (loc1.fahunItemInfo.isNeedBreak) 
                {
                    loc2 = 1;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.FahunShowTab, {"operIndex": loc2, "itemIndex": loc3}));
            }
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            return;
        }

        /* internal */ /* var */_fahunArray: Array<any>;

        /* internal */ /* var */_isClickOpen: Boolean;
    }
